﻿// Copyright (C) 2009 Choonghwan Lee (linjus.lee@gmail.com)
//
// This file is part of amanda.
//
// amanda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// amanda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with amanda. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace manager
{
	/// <summary>
	/// Interaction logic for Wizard.xaml
	/// </summary>
	public partial class Wizard : NavigationWindow
	{
		WizardData data;

		public WizardData Data
		{ get { return this.data; } }

		public Wizard()
		{
			InitializeComponent();

			WizardLauncher launcher = new WizardLauncher();
			launcher.WizardReturn += new WizardLauncher.WizardReturnEventHandler(launcher_WizardReturn);
			this.Navigate(launcher);
		}

		void launcher_WizardReturn(object sender, WizardReturnEventArgs e)
		{
			this.data = e.Data as WizardData;
			if (this.DialogResult == null)
				this.DialogResult = (e.Result == WizardResult.FINISHED);
		}
	}

	class WizardLauncher : PageFunction<WizardResult>
	{
		WizardData data;

		public event WizardReturnEventHandler WizardReturn;

		public delegate void WizardReturnEventHandler(object sender, WizardReturnEventArgs e);

		protected override void Start()
		{
			base.Start();

			this.KeepAlive = true;

			this.data = new WizardData();

			PageFunction<WizardResult> page = new Wizard1Library(this.data);
			page.Return += new ReturnEventHandler<WizardResult>(page_Return);
			this.NavigationService.Navigate(page);
		}

		void page_Return(object sender, ReturnEventArgs<WizardResult> e)
		{
			if (this.WizardReturn != null)
				this.WizardReturn(this, new WizardReturnEventArgs(e.Result, this.data));
			this.OnReturn(null);
		}
	}

	public enum WizardResult
	{
		FINISHED,
		CANCELED,
	}

	public class WizardData
	{
		public LibraryInfo LibraryInfo
		{ get; set; }
	}

	public class WizardReturnEventArgs
	{
		WizardResult result;
		WizardData data;

		public WizardReturnEventArgs(WizardResult result, WizardData data)
		{
			this.result = result;
			this.data = data;
		}

		public WizardResult Result
		{
			get { return this.result; }
		}

		public WizardData Data
		{
			get { return this.data; }
		}
	}
}
